<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;

use think\App;

class Carousel extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Carousel';

    public function index(): string
    {
        return Builder::Table()
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '标题', 'modify' => '2,input'])
            ->addColumn(['field' => 'images', 'title' => '轮播图', 'modify' => '2,img', 'templet' => '#imagesTpl'])
//            ->addColumn(['field' => 'type', 'title' => '类型', 'modify' => '2,select,getType'])
            ->addColumn(['field' => 'link', 'title' => '链接', 'modify' => '2,input'])
            ->addColumn(['field' => 'sort', 'title' => '排序', 'width' => 120, 'modify' => '2,input', 'templet' => '#sort_sort'])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120])
            ->addColumn(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200])
            ->addRightButtons(['edit', 'delete'])
            ->addSwitchTool([['name' => 'status', 'pk' => $this->pk, 'text' => '开启|关闭']])
            ->addSortTool([['name' => 'sort', 'pk' => $this->pk, 'url' => url('update')->build()]])
            ->addTopButtons(['add'])
            ->addSearch([
                ['title', '输入轮播标题', 'input', '', '', '', 'like']
            ])
            ->fetch();
    }

    public static function getType(): array
    {
        return [1 => '首页轮播图'];
    }
}
